﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Web.Services.Protocols;

namespace ISB_Data
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        Data objData = new Data();

        //[WebMethod]
        private string GetAmount(string InstId, string TxnId)
        {
            try
            {
                return objData.GetAmount(InstId, TxnId);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        [WebMethod]
        public string GetAmountByTxn(string TxnId)
        {
            try
            {
                return objData.GetAmountByTxn(TxnId);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        [WebMethod]
        public Result GetItems(string TxnId)
        {
            Result r = new Result();
            r.Message = "Success";
            r.IsSuccess = false;
            try
            {
                r.ReturnObject = objData.GetItems(TxnId);
                r.IsSuccess = true;
                return r;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                r.ErrorMessage = ex.Message;
                return r;
            }
            catch (Exception ex)
            {
                r.ErrorMessage = ex.Message;
                return r;
            }
            
        }

        [WebMethod]
        public string GetLogin(string UserName, string Password)
        {
            try
            {
                return objData.GetLogin(UserName, Password);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }   
        }

        [WebMethod]
        public Result PerformHHTransaction(long TxnId, string PeopleId, string StewardId)
        {
            Result r = new Result();
            r.Message = "Success";
            r.IsSuccess= false;
            try
            {
                objData.PerformHHTransaction(TxnId, PeopleId, StewardId);
                r.IsSuccess = true;
                return r;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                r.ErrorMessage = ex.Message;
                return r;
            }
            catch (Exception ex)
            {
                r.ErrorMessage = ex.Message;
                return r;
            }
        }

        [WebMethod]
        public string Test()
        {
            return objData.Test();
        }

        public class Result
        {
            public bool IsSuccess{get; set;}
            public string ErrorMessage{get; set;}
            public string Message{get; set;}
            public DataSet ReturnObject { get; set; }
        }
    }
}
